import os
import sys
from sqlalchemy import create_engine, text

# 测试数据库连接
def test_database_connection():
    try:
        # 使用默认的数据库URL进行测试
        database_url = 'mysql+pymysql://svt_user:password@localhost/svt_backend'
        engine = create_engine(database_url)
        
        # 测试连接
        with engine.connect() as connection:
            result = connection.execute(text("SELECT 1"))
            print("数据库连接成功!")
            print(f"测试查询结果: {result.fetchone()}")
            return True
    except Exception as e:
        print(f"数据库连接测试失败: {e}")
        return False

if __name__ == '__main__':
    test_database_connection()